package com.xiangban.yanglaodajie_admin.controller;

import com.xiangban.yanglaodajie_admin.aop.Permission;
import com.xiangban.yanglaodajie_admin.entity.Orders;
import com.xiangban.yanglaodajie_admin.entity.Shop;
import com.xiangban.yanglaodajie_admin.entity.ShopLogin;
import com.xiangban.yanglaodajie_admin.entity.dto.OrdersDto;
import com.xiangban.yanglaodajie_admin.entity.dto.ShopLoginDto;
import com.xiangban.yanglaodajie_admin.entity.res.ApiResult;
import com.xiangban.yanglaodajie_admin.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/5/28 10:00
 */
@RestController
@RequestMapping("/api/admin/shop")
@Api(tags = "后台商家")
public class ShopController {

    @Autowired
    private ShopService shopService;


    @PostMapping("/getShopOrdersList")
    @ApiOperation("店铺订单")
    @Permission(permission = "admin:shop:getShopOrdersList")
    public ApiResult getShopOrdersList(@RequestBody OrdersDto ordersDto){
        return ApiResult.newSuccess(shopService.getShopOrders(ordersDto));
    }

    @PostMapping("/getShopOrdersInfo")
    @ApiOperation("订单详情")
    @Permission(permission = "admin:shop:getShopOrdersInfo")
    public ApiResult getShopOrdersInfo(@RequestBody Orders orders){
        return ApiResult.newSuccess(shopService.getShopOrdersInfo(orders));
    }

    @PostMapping("/getOrdersClassifyNumber")
    @ApiOperation("订单类型数量")
    @Permission(permission = "admin:shop:getOrdersClassifyNumber")
    public ApiResult getOrdersClassifyNumber(@RequestBody Orders orders){
        return ApiResult.newSuccess(shopService.OrdersClassifyNumber(orders));
    }

    @PostMapping("/updateStatus")
    @ApiOperation("修改订单状态")
    @Permission(permission = "admin:shop:updateStatus")
    public ApiResult<Object> updateStatus(@RequestBody Orders orders){
        shopService.updateStatus(orders);
        return ApiResult.newSuccess();
    }

    @PostMapping("/shopIncome")
    @ApiOperation("店铺收入")
    @Permission(permission = "admin:shop:shopIncome")
    public ApiResult<Object> shopIncome(@RequestBody Orders orders){
        return ApiResult.newSuccess(shopService.todayIntegral(orders));
    }

    @PostMapping("/getShopInfo")
    @ApiOperation("获取商家信息")
    @Permission(permission = "admin:shop:getShopInfo")
    public ApiResult getShopInfo(@RequestBody Shop shop){
        return ApiResult.newSuccess(shopService.getShopInfo(shop));
    }

    @PostMapping("/updateShopInfo")
    @ApiOperation("修改商家信息")
    @Permission(permission = "admin:shop:updateShopInfo")
    public ApiResult updateShopInfo(@RequestBody Shop shop){
        shopService.updateShopInfo(shop);
        return ApiResult.newSuccess();
    }
    @PostMapping("/login")
    @ApiOperation("商家登录")
    public ApiResult<Object> login(@RequestBody ShopLogin shopLogin){
        return shopService.login(shopLogin);
    }

    @PostMapping("/logout")
    @ApiOperation("商家登出")
    public ApiResult<Object> logout(){
        shopService.losePermissionMenu();
        shopService.loseToken();
        return ApiResult.newSuccess();
    }


    @PostMapping("/shopInfo")
    @ApiOperation("获取商家权限信息")
    @Permission(permission = "admin:shop:shopInfo")
    public ApiResult<Object> shopInfo(){
        ShopLoginDto shopLoginDto = shopService.shopInfo();
        return ApiResult.newSuccess(shopLoginDto);
    }

    @GetMapping("/getCityCode")
    @ApiOperation("城市地区code码")
    public ApiResult<Object> cityCode(){
        return ApiResult.newSuccess(shopService.cityCode());
    }




//    @PostMapping("/getShopInformation")
//    @ApiOperation("商家信息(商家端)")
//    @Permission
//    public ApiResult getShopInformation(){
//        shopService.getShopInformation();
//    }

}
